﻿package com.element 
{
	import com.utils.DebugTrace;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import com.event.EventZheng
	import com.staticInfo.EventConst;
	
	/**
	 * ...
	 * @author zhengzihua
	 */
	public class Tile extends MovieClip
	{
		private var _point:Point;
		private var _allowPut:Boolean = false;//不允许摆放物件
		
		//private var coordinate:TextField;
		public function Tile() 
		{
			addEventListener(MouseEvent.CLICK, onClick);
			this.stop();
		}
		private function onClick(e:MouseEvent):void{
			var mapEvent:EventZheng = new EventZheng(EventConst.EVENT_TILE_MAP);
			mapEvent.obj.type = "click";
			mapEvent.obj.point = _point;
			parent.dispatchEvent(mapEvent);
			//stage.focus = this;
		}
		/**
		 * 检测是否能在该tile的row,cols区域摆放东西
		 * @param	row
		 * @param	cols
		 * @return
		 */
		private function checkSite(e:MouseEvent):void {
			var mapEvent:EventZheng = new EventZheng(EventConst.EVENT_TILE_MAP);
			mapEvent.obj.type = "rollOver";
			mapEvent.obj.point = _point;
			parent.dispatchEvent(mapEvent);
		}
		private function onRollOut(e:MouseEvent):void {
			var mapEvent:EventZheng = new EventZheng(EventConst.EVENT_TILE_MAP);
			mapEvent.obj.type = "rollOut";
			parent.dispatchEvent(mapEvent);
		}
		public function get point():Point { return _point; }
		
		public function set point(value:Point):void 
		{
			_point = value;
		}
		
		public function set allowPut(value:Boolean):void 
		{
			_allowPut = value;
			if (_allowPut) {
				addEventListener(MouseEvent.ROLL_OVER, checkSite);//检测鼠标移动
				addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			}else {
				removeEventListener(MouseEvent.ROLL_OVER, checkSite);
				removeEventListener(MouseEvent.ROLL_OUT, onRollOut);
			}
		}
		public function goto(num:int):void {
			gotoAndStop(num);
		}
	}
	
}